package com.example.mobile2021606159yhf0412;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class p8 extends AppCompatActivity {

    private EditText edtTxtMaina;
    private Button btnMainJisuan;
    private TextView tvMainResult;
    double bonus, bon1, bon2, bon4, bon6, bon10;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.p8);
        initView();
        bon1 = 100000 * 0.1;
        bon2 = bon1 + 100000 * 0.075;
        bon4 = bon2 + 100000 * 0.05;
        bon6 = bon4 + 100000 * 0.03;
        bon10 = bon6 + 400000 * 0.015;
    }

    private void initView() {
        edtTxtMaina = (EditText) findViewById(R.id.edtTxtMaina);
        btnMainJisuan = (Button) findViewById(R.id.btnMainJisuan);
        tvMainResult = (TextView) findViewById(R.id.tvMainResult);
    }


    public void jisuanonClick(View view) {
        String a = edtTxtMaina.getText().toString();
        if (a.length() == 0) {
            Toast.makeText(p8.this, "请输入数字", Toast.LENGTH_SHORT).show();
        } else {
            double b = Double.parseDouble(a);
            if (b <= 100000) {
                bonus = b * 0.1;
                tvMainResult.setText(String.valueOf(bonus));
            } else if (b <= 200000) {
                bonus = bon1 + (b - 100000) * 0.075;
                tvMainResult.setText(String.valueOf(bonus));
            } else if (b <= 400000) {
                bonus = bon2 + (b - 200000) * 0.05;
                tvMainResult.setText(String.valueOf(bonus));
            } else if (b <= 600000) {
                bonus = bon4 + (b - 400000) * 0.03;
                tvMainResult.setText(String.valueOf(bonus));
            } else if (b <= 1000000) {
                bonus = bon6 + (b - 600000) * 0.015;
                tvMainResult.setText(String.valueOf(bonus));
            } else {
                bonus = bon10 + (b - 1000000) * 0.01;
                tvMainResult.setText(String.valueOf(bonus));
            }
        }

    }
}
